home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / AMesaRTL.lha / Mesa-2.6 / amiga / outputhandlers / magic / magic.c next >
C/C++ Source or Header  |  1998-09-19  |  4KB  |  142 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <proto/exec.h>
  5. #include <proto/dos.h>
  6. #include <proto/utility.h>
  7.  
  8. #include <magic/magic.h>
  9. #include <magic/magic_protos.h>
  10. #include <magic/magic_pragmas.h>
  11.  
  12. #include "gl/outputhandler.h"
  13.  
  14. //
  15. // VERY simple output handler for AmigaMesaRTL
  16. // Szymon Ulatowski <szulat@friko6.onet.pl>
  17. //
  18. // 20.08.1998 - Initial version
  19. // 12.09.1998 - changed to the new driver interface
  20. //
  21. //  no configuration, uses default magic image
  22. //  (that has to be 24 bit)
  23. //  in case of any problems - silently refuses to initialize!
  24. //
  25. //  usage:
  26. //   1.start MagicServer
  27. //   2.create a magic image in any magic-aware application (eg.ImageFX)
  28. //   3.now the Mesa graphics is redirected to your application!
  29.  
  30. #define DB kprintf
  31.  
  32. AmigaMesaRTLContext ctx;
  33. UBYTE *buffer;
  34. struct Library *mesadriverBase;
  35. struct MagicBase *MagicBase;
  36. struct MagicHandle *mh;
  37. long lock;
  38. long w,h,d;
  39.  
  40. __asm __saveds int InitOutputHandlerA(register __a0 AmigaMesaRTLContext mesacontext, register __a1 struct TagItem *tags)
  41. {
  42. long mode;
  43. lock=0;
  44. buffer=0;
  45. mesadriverBase=0;
  46. MagicBase=0;
  47. mh=0;
  48. ctx = mesacontext;
  49. DB("get driver\n");
  50. Delay(50);
  51. if (!(mesadriverBase = (struct Library *)GetTagData(OH_DriverBase,NULL,tags))) goto fail;
  52. DB("get output\n");
  53. Delay(50);
  54. if (!stricmp(GetTagData(OH_OutputType,"",tags),"window"))
  55.     if (!GetTagData(OH_Output,0,tags)) goto fail;
  56. DB("get mode\n");
  57. Delay(50);
  58. AmigaMesaRTLGetContextAttr(AMRTL_Mode,mesacontext,&mode);
  59. if (mode!=AMRTL_RGBAMode) goto fail;
  60. DB("get magic\n");
  61. Delay(50);
  62. if (!(MagicBase = (struct MagicBase *)OpenLibrary(MAGIC_NAME, 34))) goto fail;
  63. DB("get image\n");
  64. Delay(50);
  65. if (!(mh = OpenMagicImage(NULL, NULL, TAG_END))) goto fail;
  66. DB("get sizes\n");
  67. Delay(50);
  68. w = mh->Object->Width;
  69. h = mh->Object->Height;
  70. d = mh->Object->Depth;
  71. buffer=malloc(w);
  72. if (d!=3) goto fail;
  73. DB("lock image\n");
  74. Delay(50);
  75. if (!(AttemptLockMagicImage(mh, LMI_Write))) goto fail;
  76. DB("everything ok\n");
  77. Delay(50);
  78. lock=1;
  79.     return 1;
  80.  
  81. fail:
  82.     DeleteOutputHandler();
  83.     return 0;
  84. }
  85.  
  86. __asm __saveds void DeleteOutputHandler(void)
  87. {
  88. DB("delete\n");
  89. Delay(50);
  90. if (lock) UnlockMagicImage(mh);
  91. lock=0;
  92. if (buffer) free(buffer);
  93. buffer=0;
  94. if (mh) CloseMagicImage(mh);
  95. mh=0;
  96. if(MagicBase) CloseLibrary(MagicBase);
  97. MagicBase=0;
  98. }
  99.  
  100. __asm __saveds int ResizeOutputHandler(void)
  101. {return 1;}
  102.  
  103. __asm __saveds int ProcessOutput(void)
  104. {
  105. UBYTE *src,*rgb,*dst;
  106. int y,bw,x;
  107. AmigaMesaRTLGetContextAttr(AMRTL_Buffer,ctx,&rgb);
  108. AmigaMesaRTLGetContextAttr(AMRTL_BufferWidth,ctx,&bw);
  109. DB("process output\n");
  110.  
  111. for (y=0;y<h;y++,rgb+=(4*bw))
  112.     {
  113. //   if (!(PutMagicImageData(mh, y, 1, GMI_RGBA, rgb, TAG_END))) return 0;
  114.     for (x=w,src=rgb,dst=buffer;x>0;x--,dst++,src+=4) (*dst)=(*src);
  115.       if (!(PutMagicImageData(mh, y, 1, GMI_Red, buffer, TAG_END))) return 0;
  116.     for (x=w,src=rgb+1,dst=buffer;x>0;x--,dst++,src+=4) (*dst)=(*src);
  117.       if (!(PutMagicImageData(mh, y, 1, GMI_Green, buffer, TAG_END))) return 0;
  118.     for (x=w,src=rgb+2,dst=buffer;x>0;x--,dst++,src+=4) (*dst)=(*src);
  119.       if (!(PutMagicImageData(mh, y, 1, GMI_Blue, buffer, TAG_END))) return 0;
  120.     }
  121. RedrawMagicImage(mh,0,0,w,h);
  122.     return 1;
  123. }
  124.  
  125. __asm __saveds void SetIndexRGBTable(register __d0 int index, register __a0 ULONG *rgbtable, register __d1 int numcolours)
  126. { }
  127.  
  128. __asm __saveds ULONG SetOutputHandlerAttrsA(register __a0 struct TagItem *tags)
  129. { return 0; }
  130.  
  131. __asm __saveds ULONG GetOutputHandlerAttr(register __d0 ULONG attr, register __a0 ULONG *data)
  132. {
  133. switch(attr)
  134.     {
  135.         case OH_Width: *data = w; break;
  136.         case OH_Height: *data = h; break;
  137.         default:        return(0);
  138.     }
  139. return(1);
  140. }
  141.  
  142.